<template>
    <view>
      <uni-row style="margin: 10px">
        <uni-col>
          <uni-datetime-picker v-model="queryParams.violationDay" @change="onViolationDayChange" type="date" />
        </uni-col>
      </uni-row>

      <uni-list :border="true" style="margin-left: 10px;margin-right: 10px;margin-bottom: 10px">
        <uni-list-item
            thumb-size="lg"
            :title="getDictLabel(violationTypeOptions,item.violationType)"
            :thumb="handleImageUrl(item.cover)"
            :note="item.violationTime"
            v-for="(item,index) in violationPatrolList"
            :key="index"
            @click="goToDetail(item)" link>
          <template v-slot:footer>
            <uni-badge type="success" :text="item.statusText" size="normal" style="align-self: center;" :custom-style="{fontSize: '13px'}" />
          </template>
        </uni-list-item>
      </uni-list>
    </view>
</template>

<script>
import violationPatrol from "@/api/modules/violationPatrol";
import {getDictByType} from "../../../api/modules/sys";
import {getDictLabel} from "../../../js/common";
export default {
  data() {
    return {
      queryParams: {
        "violationDay": null,
        "gtStatus": 1
      },
      violationPatrolList: [],
      violationTypeOptions: null,
    }
  },
  onShow() {
    this.showLoadingByQuery();
    getDictByType("violation_type").then(res=>{
      this.violationTypeOptions = res.data;
      this.getViolationPatrolPage();
    }).catch(error=>{
      this.hideLoading();
      if(this.isEmpty(this.violationTypeOptions)){
        this.toast(this.getErrorResMsg(error,"获取数据失败"));
        this.goBack(1000);
      }
    });
  },
  methods: {
    getDictLabel,
    goToDetail(item) {
      console.log("打开违纪认领页面",item);
      // 点击事件，跳转到详情页面
      uni.navigateTo({
        url: `/pages_duty/classTeacher/violation/violationReceiveDetail?id=${item.id}`
      });
    },
    getViolationPatrolPage(){
      violationPatrol.getViolationPatrolPageList(this.queryParams).then(res=>{
        this.hideLoading();
        this.violationPatrolList = res.data.list;
      }).catch(()=>{
        this.hideLoading();
      });
    },
    onViolationDayChange(val){
      console.log("onViolationDayChange() day:",val)
      if(!val){
        this.queryParams.violationDay = null;
      }
      this.getViolationPatrolPage();
    }
  }
}
</script>

<style>
</style>
